package cn.lbaicai.service.imp;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.lbaicai.dao.UserDao;
import cn.lbaicai.entity.ResultData;
import cn.lbaicai.entity.User;
import cn.lbaicai.service.UserService;
@Service
public class UserServiceImp implements UserService {
	@Autowired
	private UserDao userDao;
	public User selectByUser(User user) {
		User users = userDao.selectByUser(user);
		if(users!=null){
			return users;
		}
		// TODO Auto-generated method stub
		return null;
	}
	public int insertSelective(User record) {
		return userDao.insertSelective(record);
	}
	public ResultData<List<User>> selectByMap(Map<String, Object> param) {
		ResultData<List<User>> resultData = new ResultData<List<User>>();
		int page = (Integer) param.get("page");
		int limit =  (Integer) param.get("limit");
		int pageCount = (page-1)*limit;
		param.put("pageCount",pageCount);
		// TODO Auto-generated method stub
		List<User> users= userDao.selectByMap(param);
		if(users.size()>0){
			resultData.setCode(200);
			resultData.setMsg("查询成功");
			resultData.setData(users);
			int count = userDao.selectByUserCount(param);
			resultData.setCount(String.valueOf(count));
		}else{
			resultData.setCode(201);
			resultData.setMsg("未查到数据");
		}
		return resultData;
	}
	public User selectByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return userDao.selectByPrimaryKey(id);
	}

}
